<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Index_index_module extends CI_Module {

    public $scenic_model;
    private $sid ;
    /**
     * 构造函数
     */
    public function __construct()
    {
        parent::__construct();
        if(check_wap()&&$_GET['type']!='pc'){
            if($this->uri->segment(1) == 'xianlu'){
                $lind = intval($this->uri->segment(2));
                header("Location: ".site_url('mobile/line/profile/?id='.$lind), TRUE);
                exit;
            }
            header("Location: ".site_url('mobile/index'), TRUE, 302);
            exit;
        }

 



        $this->data = array();
        $this->nav = array();
        $this->sid = $GLOBALS['sid'];
        //网站配置信息
        $this->data = $GLOBALS['config'];
        //中部导航栏
        $nav_list = $this->Nav_model->get_index_nav_list('is_open=1 AND page_type=1');
        $this->nav = $nav_list;
    }

    public function index()
    {
        //旅游资讯
        $cat_name = '资讯';
        $ids = $this->Articlecat_model->get_row(array('cat_name' => $cat_name,'sid'=>$this->sid));
        if(!empty($ids)){
            $ids = $ids['cat_id'];
            $table = $this->db->dbprefix("article");
//            $ids = substr($ids,1);
            $where = $table.".cat_id IN (".$ids.") AND $table.is_open=1 AND $table.sid=$this->sid ";
            $information = $this->Article_model->get_information(8,1,$where);
            $data['information'] = $information;
        }
        //十大美景
        $data['sitelogo'] = $this->data['sitelogo'] ;
        $data['params'] = array(
            'seo'=>array('title'=>SITECITYNAME.'旅游攻略','keywords'=>SITECITYNAME.'旅游网,'.SITECITYNAME.'市旅游局','desc'=>SITECITYNAME.'旅游网-'.SITECITYNAME.'旅游局主办，为您提供'.SITECITYNAME.'旅游资讯、'.SITECITYNAME.'旅游攻略、'.SITECITYNAME.'旅游线路，包括'.SITECITYNAME.'热门景区介绍、精彩游记、旅游地图、交通出行、游玩路线、旅游优惠信息、住宿、饮食、购物等旅游信息的综合性旅游门户网站。'),
            'nav'=>array('current'=>'home'),
        );

        $this->load->view(TEMPLATE_NAME.'/body',$data);

    }

    private function _get_line_info($line){
        $line_ids = array();
        foreach ($line as $k => $v) {
            $m = array();
            preg_match('/.*?(\d+).*?/', $v['link_url'], $m);
            if(isset($m[1])){
                $line_ids[$k] = $m[1];
            }
        }
        if($line_ids){
            $result = array();
            $condition = array(
                'page'=>1 ,
                'page_size'=>count($line),
                'cat_id'=>0,
                'expand_1'=>0,
                'd_city'=>0,
                'city'=>0,
                'product_sort'=>0,
                'keywords'=>'',
                'mark'=>0
            );
            $return = $this->Line_model->get_list_m($condition, 'a.line_id in (' . implode(',', $line_ids) .')');

            foreach (@$return['data'] as $k => $v) {
                $result[$v['line_id']] = $v;
            }

            foreach ($line as $k => $v) {
                @$line[$k]['line_info'] = $result[$line_ids[$k]];
            }
        }
        return $line;
    }

    /**
     * 头部信息
     * @param array $seo SEO信息  title=>'标题','keywords'=>关键字,'desc'=> 描述
     * @param array $nav 高亮信息  current=> '主导航高亮参数'
     * @param array $search 查询信息 type=> '类型' ,keywords=>'查询关键字'
     */
    public function head($seo=array(),$nav=array('current'=>'home'),$search=array('type'=>1,'type_name'=>'线路','keywords'=>'')){
        $data['middle_nav'] = isset($this->nav['middle'])?$this->nav['middle']:array();

        $data['type']       = $search['type'];
        $data['keywords']   = $search['keywords'];
        $data['search_url'] = '';
        switch ($data['type']){
        	case 1:
        		$data['search_url'] = site_url('line/index/search');
        	    break;
        	case 2:
        		$data['search_url'] = site_url('ticket/index/search');
        	    break;
        	case 3:
        		$data['search_url'] = site_url('hotel/index/search');
        	    break;
        	default:
        		$data['search_url'] = site_url('line/index/search');
        	    break;
        }
        //seo信息
        $data['seo'] = $seo;
        //导航控制
        $data['nav'] = $nav;
        $data['search'] = $search;
        $data['site'] = $this->data;
        $data['sitelogo'] = $this->data['sitelogo'];
        @$data['site_ico'] = $this->data['site_ico'];
        $data['site_wx_qr'] = isset($this->data['site_wx_qr'])?$this->data['site_wx_qr']:'';
        $data['weibo_link'] = isset($this->data['weibo_link'])?$this->data['weibo_link']:'';
        $data['weibo_qrcode'] = isset($this->data['site_wx_qr'])?$this->data['weibo_qrcode']:'';
        $data['wap_index_url'] = isset($this->data['wap_index_url'])?site_url('mobile/index'):$this->data['wap_index_url'];
        $this->load->view(TEMPLATE_NAME.'/head',$data);
    }

    /**
     * 底部信息
     */
    public function foot($param=array()){
        //访问量
//        $res = $this->Site_view_model->update_data();
        //网站配置信息
        $data['site'] = $this->data;
        //底部导航
        $data['bottom_nav'] = isset($this->nav['bottom'])?$this->nav['bottom']:array();

        //网站信息验证
        $verif_list = $this->Siteverif_model->get_list('100','1','is_open=1');
        $data['verif_list'] = $verif_list;

        if(@$param['friend_link']){
        //网站友情链接 图片
        $where = " is_open=1 AND cat_type='pic'";
        $friend_link = $this->Friendlink_model->get_list('100','1',$where);
        $data['friend_link'] = $friend_link;

        //网站友情链接 文字
        $where = " is_open=1 AND cat_type='text'";
        $friend_link_text = $this->Friendlink_model->get_list('100','1',$where);
        $data['friend_link_text'] = $friend_link_text;
        }
        $data['site_code'] = $GLOBALS['config']['site_code'];

        $this->load->view(TEMPLATE_NAME.'/foot',$data);
    }

    /**
     * 携程共建频道头部
     * @param array $seo
     * @param array $nav
     * @param array $search
     */
    public function head_ctrip($seo=array(),$nav=array('current'=>'home'),$search=array('type'=>1,'type_name'=>'线路','keywords'=>'')){
        $data['middle_nav'] = isset($this->nav['middle'])?$this->nav['middle']:array();

        $data['type']       = $search['type'];
        $data['keywords']   = $search['keywords'];
        $data['search_url'] = '';
        switch ($data['type']){
            case 1:
                $data['search_url'] = site_url('line/index/search');
                break;
            case 2:
                $data['search_url'] = site_url('ticket/index/search');
                break;
            case 3:
                $data['search_url'] = site_url('hotel/index/search');
                break;
            default:
                $data['search_url'] = site_url('line/index/search');
                break;
        }
        //seo信息
        $data['seo'] = $seo;
        //导航控制
        $data['nav'] = $nav;
        $data['search'] = $search;
        $data['site'] = $this->data;
        $data['sitelogo'] = $this->data['sitelogo'];
        @$data['site_ico'] = $this->data['site_ico'];
        $this->load->view(TEMPLATE_NAME.'/head_ctrip',$data);
    }

    /**
     * 携程共建频道尾部
     */
    public function foot_ctrip(){

        //访问量
//        $res = $this->Site_view_model->update_data();
        //网站配置信息
        $data['site'] = $this->data;
        //底部导航
        $data['bottom_nav'] = isset($this->nav['bottom'])?$this->nav['bottom']:array();

        //网站信息验证
        $verif_list = $this->Siteverif_model->get_list('100','1','is_open=1');
        $data['verif_list'] = $verif_list;

        //网站友情链接
        $where = " is_open=1 AND cat_type='pic'";
        $friend_link = $this->Friendlink_model->get_list('100','1',$where);
        $data['friend_link'] = $friend_link;

        //帮助中心
        $help_list = $this->Article_model->get_help_list();
        $data['help_list'] = $help_list;

        $this->load->view(TEMPLATE_NAME.'/foot_ctrip',$data);
    }

    /**
     * 面包屑
     */
    public function bread($bread=array()){
        $data = array();
        $data['bread'] = $bread;
        $this->load->view(TEMPLATE_NAME.'/bread',$data);
    }

    /**
     * 城市站面包屑
     */
    public function bread_city($bread=array()){
        $data = array();
        $data['bread'] = $bread;
        $this->load->view(TEMPLATE_NAME.'/bread_city',$data);
    }

    /**
     *
     */
    public function page_header(){
        $this->load->view(TEMPLATE_NAME.'/page_header');
    }

    /**
     * 会员登陆，注册头部
     */
    public function login_register_header(){

        $data['site'] = $this->data;
        $data['sitelogo'] = $this->data['sitelogo'];
        @$data['site_ico'] = $this->data['site_ico'];
        $this->load->view(TEMPLATE_NAME.'/login_register_header',$data);
    }

    /**
     * 会员登陆，注册底部
     */
    public function login_register_footer(){

        //网站配置信息
        $data['site'] = $this->data;
        //底部导航
        $data['bottom_nav'] = isset($this->nav['bottom'])?$this->nav['bottom']:array();

        $this->load->view(TEMPLATE_NAME.'/login_register_footer',$data);
    }

    /**
     * 订单头部
     */
    public function order_header(){
        $data = array();
        $data['site'] = $this->data;
        $data['sitelogo'] = $this->data['sitelogo'];
        @$data['site_ico'] = $this->data['site_ico'];
        //底部导航
        $data['bottom_nav'] = isset($this->nav['bottom'])?$this->nav['bottom']:array();
        $this->load->view(TEMPLATE_NAME.'/order_header',$data);
    }

    /**
     * 订单底部
     */
    public function order_footer(){
        //访问量
//        $res = $this->Site_view_model->update_data();
        $data = array('site'=>$this->data);
        //底部导航
        $data['bottom_nav'] = isset($this->nav['bottom'])?$this->nav['bottom']:array();
        $this->load->view(TEMPLATE_NAME.'/order_footer',$data);
    }

    /**
     * 城市站顶部页面
     * @param array $seo
     * @param array $nav
     * @param array $search
     */
    public function head_citysite($seo=array(),$nav=array('current'=>'home'),$search=array('type'=>1,'type_name'=>'线路','keywords'=>'')){

        //中部导航栏
        $nav_list = $this->Nav_model->get_index_nav_list('is_open=1 AND page_type=2');
        $data['middle_nav'] = isset($nav_list['middle'])?$nav_list['middle']:array();
        $data['second_middle_nav'] = isset($this->nav['middle'])?$this->nav['middle']:array();
        $data['type']       = $search['type'];
        $data['keywords']   = $search['keywords'];
        $data['search_url'] = '';
        switch ($data['type']){
            case 1:
                $data['search_url'] = site_url('line/index/search');
                break;
            case 2:
                $data['search_url'] = site_url('ticket/index/search');
                break;
            case 3:
                $data['search_url'] = site_url('hotel/index/search');
                break;
            default:
                $data['search_url'] = site_url('line/index/search');
                break;
        }
        //seo信息
        $data['seo'] = $seo;
        //导航控制
        $data['nav'] = $nav;
        $data['search'] = $search;
        $data['site'] = $this->data;
        $data['sitelogo'] = $this->data['sitelogo'];
        @$data['site_ico'] = $this->data['site_ico'];
        $data['site_wx_qr'] = isset($this->data['site_wx_qr'])?$this->data['site_wx_qr']:'';
        $data['wap_index_url'] = isset($this->data['site_wx_qr'])?site_url('mobile/index'):$this->data['site_wx_qr'];
        $this->load->view(TEMPLATE_NAME.'/head_citysite',$data);
    }

    /**
     * 城市站主导航
     */
    public function head_nav_citysite(){

        //中部导航栏
        $nav_list = $this->Nav_model->get_index_nav_list('is_open=1 AND page_type=2');
        $data['middle_nav'] = isset($nav_list['middle'])?$nav_list['middle']:array();
        $this->load->view(TEMPLATE_NAME.'/head_nav_citysite',$data);
    }

    /**
     * 城市站尾部页面
     */
    public function foot_citysite(){

        //访问量
//        $res = $this->Site_view_model->update_data();
        //网站配置信息
        $data['site'] = $this->data;

        //底部导航
        $nav_list = $this->Nav_model->get_index_nav_list('is_open=1 AND page_type=2');
        $data['bottom_nav'] = isset($nav_list['bottom_nav'])?$nav_list['bottom_nav']:array();

        //网站信息验证
        $verif_list = $this->Siteverif_model->get_list('100','1','is_open=1');
        $data['verif_list'] = $verif_list;

        //网站友情链接
        $where = " is_open=1 AND cat_type='pic'";
        $friend_link = $this->Friendlink_model->get_list('100','1',$where);
        $data['friend_link'] = $friend_link;

        //帮助中心
        $help_list = $this->Article_model->get_help_list();
        $data['help_list'] = $help_list;

        $this->load->view(TEMPLATE_NAME.'/foot_citysite',$data);
    }

    /**
     * 头部信息 当有两个头时使用
     * @param array $seo SEO信息  title=>'标题','keywords'=>关键字,'desc'=> 描述
     * @param array $nav 高亮信息  current=> '主导航高亮参数'
     * @param array $search 查询信息 type=> '类型' ,keywords=>'查询关键字'
     */
    public function head_second($seo=array(),$nav=array('current'=>'home'),$search=array('type'=>1,'type_name'=>'线路','keywords'=>'')){
        $data['middle_nav'] = isset($this->nav['middle'])?$this->nav['middle']:array();

        $data['type']       = $search['type'];
        $data['keywords']   = $search['keywords'];
        $data['search_url'] = '';
        switch ($data['type']){
            case 1:
                $data['search_url'] = site_url('line/index/search');
                break;
            case 2:
                $data['search_url'] = site_url('ticket/index/search');
                break;
            case 3:
                $data['search_url'] = site_url('hotel/index/search');
                break;
            default:
                $data['search_url'] = site_url('line/index/search');
                break;
        }
        //seo信息
        $data['seo'] = $seo;
        //导航控制
        $data['nav'] = $nav;
        $data['search'] = $search;
        $data['site'] = $this->data;
        $data['sitelogo'] = $this->data['sitelogo'];
        @$data['site_ico'] = $this->data['site_ico'];
        $data['site_wx_qr'] = isset($this->data['site_wx_qr'])?$this->data['site_wx_qr']:'';
        $data['weibo_link'] = isset($this->data['weibo_link'])?$this->data['weibo_link']:'';
        $data['weibo_qrcode'] = isset($this->data['site_wx_qr'])?$this->data['weibo_qrcode']:'';
        $data['wap_index_url'] = isset($this->data['wap_index_url'])?site_url('mobile/index'):$this->data['wap_index_url'];
        $this->load->view(TEMPLATE_NAME.'/head_second',$data);
    }

    function zidian(){
        $dbserver   = "61.147.75.105";
        $dbusername = "wkm";
        $dbpassword = '123456';
        $database   = "cloud_system";
        $mysql_conn = @mysql_connect("$dbserver", "$dbusername", "$dbpassword") or die("Mysql connect is error.");
        mysql_select_db($database, $mysql_conn);
        mysql_query('SET NAMES utf8', $mysql_conn);
//mysql_query('SET NAMES gbk', $mysql_conn);
        $table_result = mysql_query('show tables', $mysql_conn);
//取得所有的表名
        while ($row = mysql_fetch_array($table_result)) {
            $tables[]['TABLE_NAME'] = $row[0];
        }

//循环取得所有表的备注及表中列消息
        foreach ($tables AS $k=>$v) {
            $sql  = 'SELECT * FROM ';
            $sql .= 'INFORMATION_SCHEMA.TABLES ';
            $sql .= 'WHERE ';
            $sql .= "table_name = '{$v['TABLE_NAME']}' AND table_schema = '{$database}'";
            $table_result = mysql_query($sql, $mysql_conn);
            while ($t = mysql_fetch_array($table_result) ) {
                $tables[$k]['TABLE_COMMENT'] = $t['TABLE_COMMENT'];
            }

            $sql  = 'SELECT * FROM ';
            $sql .= 'INFORMATION_SCHEMA.COLUMNS ';
            $sql .= 'WHERE ';
            $sql .= "table_name = '{$v['TABLE_NAME']}' AND table_schema = '{$database}'";

            $fields = array();
            $field_result = mysql_query($sql, $mysql_conn);
            while ($t = mysql_fetch_array($field_result) ) {
                $fields[] = $t;
            }
            $tables[$k]['COLUMN'] = $fields;
        }
        mysql_close($mysql_conn);


        $html = '';
//循环所有表
        $foo = 1;
        foreach ($tables AS $k=>$v) {
            //$html .= '<p><h2>'. $v['TABLE_COMMENT'] . '&nbsp;</h2>';
            $html .= '<table  border="1" cellspacing="2" cellpadding="2" align="center">';
            $html .= '<caption>[' . $foo++ . ']' . $v['TABLE_NAME'] .'  '. $v['TABLE_COMMENT']. '</caption>';
            $html .= '<tbody><tr>
	          <th>编号</th>
	          <th>字段名</th>
	          <th>数据类型</th>
	          <th>默认值</th>
			  <th>允许非空</th>
			  <th>自动递增</th>
			  <th>备注</th>
			  <th>对应原库字段</th></tr>';
            $html .= '';

            foreach ($v['COLUMN'] AS $k1=>$f) {
                $html .= '<tr><td align="center">'.$k1.'</td><td class="c1">' . $f['COLUMN_NAME'] . '</td>';
                $html .= '<td class="c2">' . $f['COLUMN_TYPE'] . '</td>';
                $html .= '<td class="c3">&nbsp;' . $f['COLUMN_DEFAULT'] . '</td>';
                $html .= '<td class="c4">&nbsp;' . $f['IS_NULLABLE'] . '</td>';
                $html .= '<td class="c5">' . ($f['EXTRA']=='auto_increment'?'是':'&nbsp;') . '</td>';
                $html .= '<td class="c6">&nbsp;' . $f['COLUMN_COMMENT'] . '</td>';
                $html .= '<td class="c7">&nbsp;</td>';
                $html .= '</tr>';
            }
            $html .= '</tbody></table></p>';
        }

//输出
        echo '<html>
		<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>'.$title.'</title>
		<style>
		body,td,th {font-family:"宋体"; font-size:12px;}
		table{border-collapse:collapse;border:1px solid #CCC;background:#efefef;}
		table caption{text-align:left; background-color:#fff; line-height:2em; font-size:14px; font-weight:bold; }
		table th{text-align:left; font-weight:bold;height:26px; line-height:26px; font-size:12px; border:1px solid #CCC;}
		table td{height:24px; font-size:12px; border:1px solid #CCC;background-color:#fff;}
		.c1{ width: 120px;}
		.c2{ width: 120px;}
		.c3{ width: 50px;}
		.c4{ width: 60px;}
		.c5{ width: 60px;}
		.c6{ width: 220px;}
		.c7{ width: 220px;}
		</style>
		</head>
		<body>';
        echo '<h1 style="text-align:center;">'.$title.'</h1>';
        echo $html;
        echo '</body></html>';
        exit;

    }


    function site_views(){
        //网站访问量
        $this->Site_view_model->update_data();
        $res = array('code'=>1,'msg'=>'更新成功');
        echo json_encode($res);exit;
    }
    //线路访问量
    function line_views(){
        $id =  $this->input->get_post('id');
        $this->Line_model->update_visits($id);
        $this->Line_view_model->update_data('views');
        $res = array('code'=>1,'msg'=>'更新成功');
        echo json_encode($res);exit;
    }
}